//===================================================================================
// Microsoft patterns & practices
// Composite Application Guidance for Windows Presentation Foundation and Silverlight
//===================================================================================
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===================================================================================
using System.Globalization;
using System.Windows.Data;
using System;

namespace BlueMarble.Genesis.Infrastructure.Converters
{
    public class EnumVisibilityConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
        {
            if ((string)parameter == "Private")
            {
                if ((Int32)value == 1)
                {
                    value = System.Windows.Visibility.Visible;
                }
                else
                {
                    value = System.Windows.Visibility.Collapsed;
                }
            }
            else if ((string)parameter == "Company")
            {
                if ((Int32)value == 2)
                {
                    value = System.Windows.Visibility.Visible;
                }
                else
                {
                    value = System.Windows.Visibility.Collapsed;
                }
            }
            return value;
        }

        public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture)
        {
            var result = value as System.Windows.Visibility?;

            if ((string)parameter == "Private")
            {
                if (result == System.Windows.Visibility.Visible)
                    value = 1;
                else
                    value = 2;
            }
            else if ((string)parameter == "Company")
            {
                if (result == System.Windows.Visibility.Visible)
                    value = 2;
                else
                    value = 1;
            }

            return value;

        }

        #endregion
    }
}